package team.yidong.fenda.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import team.yidong.fenda.entity.Master;

import java.util.List;

/**
 * Created by xuanlong on 2017/10/15.
 */
@Repository
public interface MasterRepository extends JpaRepository<Master, Integer>, JpaSpecificationExecutor<Master> {
    @Query("select master from Master master join master.hospital hospital where hospital.id=?1 and master.isBlack<>'是'")
    List<Master> findMaster(Integer hospitalId);

    @Query("select master from Master master join master.hospital hospital where hospital.name=?1 and master.name=?2")
    Master findMasterByHospitalNameAndName(String hospitalName, String masterName);

    List<Master> findByIsBlack(String isBlack);

    Master findByOpenId(String openId);

    Master findByUserName(String userName);

    Master findByUserNameAndPassword(String userName, String password);

    List<Master> findByHospitalDepartmentId(Integer hospitalDepartmentId);

    @Query("select master from Master master join master.hospital hospital where hospital.id=?1")
    List<Master> findByHospitalId(Integer hospitalId);
}
